package com.zhentao.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.domain.SysActivity;
import com.zhentao.domain.dto.PageDto;
import com.zhentao.service.SysActivityService;
import com.zhentao.mapper.SysActivityMapper;
import org.springframework.stereotype.Service;
import io.micrometer.common.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Map;

/**
* @author 86133
* @description 针对表【sys_activity】的数据库操作Service实现
* @createDate 2024-09-06 10:00:56
*/
@Service
public class SysActivityServiceImpl extends ServiceImpl<SysActivityMapper, SysActivity>
    implements SysActivityService{
//活动增删改查
    @Override
    public int addActivity(SysActivity activity) {
        boolean save = this.save(activity);
        return save ? 1 : 0;
    }
//删除
    @Override
    public int deleteActivity(Integer id) {
        boolean remove = this.removeById(id);
        return remove ? 1 : 0;
    }

    @Override
    public int updateActivity(SysActivity activity) {
        boolean updateById = this.updateById(activity);
        return updateById ? 1 : 0;
    }
//活动查询+分页+条件查询
    @Override
    public Page<SysActivity> queryActivityByPage(PageDto pageDto) {
        Page<SysActivity> page = new Page<>(pageDto.getPage(), pageDto.getSize());
        LambdaQueryWrapper<SysActivity> wrapper = new LambdaQueryWrapper<>();
        Map<String, Object> map = pageDto.getMap();
        wrapper.like(StringUtils.isNotBlank((String) map.get("activityName")),SysActivity::getActivityName,pageDto.getMap().get("activityName"))
                .gt(StringUtils.isNotBlank((String) pageDto.getMap().get("startTime")),SysActivity::getStartTime,pageDto.getMap().get("startTime"))
                .le(StringUtils.isNotBlank((String) pageDto.getMap().get("endTime")),SysActivity::getEndTime,pageDto.getMap().get("endTime"));
        this.page(page,wrapper);
        return page;
    }


}




